<?php
$id = empty($_GET['id']) ? 0 : intval($_GET['id']);
if($id == 0 && empty($_GET['filename'])){
	go(PUB_DIR.'news/');
}
$oNews = new News();
if(!empty($_GET['filename'])){
	$news = $oNews->get_by_filename($_GET['filename'], '*');
}else{
	$news = $oNews->get_row($id, '*');
}
if(empty($news)){
	go(PUB_DIR.'news/');
}
if(!empty($news['url'])){
	go($news['url']);
}
$news_categorys = cache_read('news_categorys.php');
$news['catname'] = $news_categorys['category_list'][$news['catid']]['name'];
$news['publishtime'] = empty($news['updatetime']) ? fdate($news['addtime']) : fdate($news['updatetime']);
$vars['news'] = $news;

// 上一新闻、下一新闻
$news_prev = $oNews->get_prev($news['rank'], $news['id'], '`id`,`title`,`url`,`filename`,`addtime`');
if(!empty($news_prev)){
	if(empty($news_prev['url'])){
		if(empty($news_prev['filename'])){
			$news_prev['url'] = PUB_DIR.'news/'.time_to_path($news_prev['addtime']).'/'.$news_prev['id'].'.html';
		}else{
			$news_prev['url'] = PUB_DIR.'news/v/'.$news_prev['filename'].'.html';
		}
	}
	$vars['news_prev'] = $news_prev;
}
$news_next = $oNews->get_next($news['rank'], $news['id'], '`id`,`title`,`url`,`filename`,`addtime`');
if(!empty($news_next)){
	if(empty($news_next['url'])){
		if(empty($news_next['filename'])){
			$news_next['url'] = PUB_DIR.'news/'.time_to_path($news_next['addtime']).'/'.$news_next['id'].'.html';
		}else{
			$news_next['url'] = PUB_DIR.'news/v/'.$news_next['filename'].'.html';
		}
	}
	$vars['news_next'] = $news_next;
}

/*******************************************************************************
 * 页面信息　& 当前位置
 *******************************************************************************/
if($__f_sysvars['url_rewrite'] == 'html' || $__f_sysvars['url_rewrite'] == 'rewrite'){
	if(empty($news['filename'])){
		$url = PUB_DIR.'news/'.time_to_path($news['addtime']).'/'.$id.'.html';
	}else{
		$url = PUB_DIR.'news/v/'.$news['filename'].'.html';
	}
}else{
	$url = WEB_DIR."index.php?mdl=news&do=view&id={$news['id']}";
}
url_here($news['title'], $url);
url_here($news['catname'], PUB_DIR."news/{$news_categorys['category_list'][$news['catid']]['mark']}/");
$__pageinfo['keywords'] = "{$news['title']}";
$__pageinfo['description'] = $news['summary'];
?>